home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / snip9503 / prntself.c < prev    next >
C/C++ Source or Header  |  1995-03-14  |  734b  |  36 lines

  1. /*
  2. **  PRNTSELF.C - A program which prints its own source
  3. **
  4. **  public domain demo by Bob Stout
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9.  
  10. main(int argc, char *argv[])
  11. {
  12.       FILE *in;
  13.       char fname[13], *ptr;
  14.       char line[1024];        /* Nice & roomy   */
  15.  
  16.       /*
  17.       ** Get the source name by replacing the executable's COM or EXE with C
  18.       */
  19.  
  20.       strcpy(fname, argv[0]);
  21.       ptr = strrchr(fname, '.');
  22.       strcpy(++ptr, "C");
  23.  
  24.       /*
  25.       ** Print its own source
  26.       */
  27.  
  28.       if (NULL != (in = fopen(fname, "r")))
  29.       {
  30.             while (NULL != fgets(line, 1023, in))
  31.                   fputs(line, stdprn);
  32.             return 0;
  33.       }
  34.       else  return -1;
  35. }
  36.